package com.hc.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Component
@Aspect
@Slf4j
public class GlobalLogRecord {


    @Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)||@annotation(org.springframework.web.bind.annotation.PostMapping))||@annotation(org.springframework.web.bind.annotation.GetMapping)")
    public void outputLog(JoinPoint joinPoint){
        String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        String name = signature.getMethod().getName();
       // String nowYmdhmm = DateUtils.getNowYmdhmm();
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if(null!=attributes){
            HttpServletRequest request = attributes.getRequest();
          //  Map<String, String> parameterAndValue = ScbRequestUtils.getParameterAndValue(request);
            LogRecord logRecord =new LogRecord();
           // logRecord.setDate(nowYmdhmm);
            logRecord.setClassName(className);
            logRecord.setMethodName(name);
           // logRecord.setParams(parameterAndValue);
           // log.info(JSONArray.toJSONString(logRecord));
        }
    }

}
